import AjaxForBusOpen from '@/utils/AjaxForBusOpen'
import EndStationModel from '../models/EndStationModel'
/**
 * 获取目的地列表
 *
 */
async function getStationList(test = false) {
  let res
  if (test) {
    res = {
      LIST: [
        {
          END_STATION_ID: '1',
          END_STATION_NAME: '嘉定客运中心'
        },
        {
          END_STATION_ID: '11',
          END_STATION_NAME: '虹桥西交通中心'
        },
        {
          END_STATION_ID: '22',
          END_STATION_NAME: '嘉定西站'
        }
      ]
    }
  } else {
    res = await AjaxForBusOpen('customLine/userDemand/endStation/list', {})
  }
  let endStationList = []
  res.LIST.map(item => {
    endStationList.push(
      new EndStationModel(item.END_STATION_ID, item.DESTINATION_NAME)
    )
  })
  let body = [
    {
      values: endStationList,
      defaultIndex: 0,
      textAlign: 'center'
    }
  ]
  return body
}

/**
 * 提交定制需求
 *
 */
async function onAddCustomDemand(data) {
  // console.log(data, 'data')
  let startTime =
    data.dateStartTimeValueArr[1] + ':' + data.dateStartTimeValueArr[2]
  let endTime = data.dateEndTimeValueArr
    ? data.dateEndTimeValueArr[1] + ':' + data.dateEndTimeValueArr[2]
    : null
  let sendObj = {
    START_STATION: {
      ADDRESS: data.startSite.NAME,
      ADDRESS_LNG: data.startSite.LONGITUDE,
      ADDRESS_LAT: data.startSite.LATITUDE
    },
    END_STATION_ID: data.siteInfo.endStationId,
    START_TIME: startTime,
    START_RIDE_BUS_FREQUENCY: data.deteStartTimeArrFirstValue,
    END_TIME: endTime,
    END_RIDE_BUS_FREQUENCY: data.dateEndTimeArrFirstValue
      ? data.dateEndTimeArrFirstValue
      : null,
    USER_REMARK: data.textareaValue
  }
  // console.log(sendObj, 'sendObj')
  await AjaxForBusOpen('customLine/userDemand/add', sendObj, 1)
}

export { getStationList, onAddCustomDemand }
